﻿using System;

namespace NetAssist.Pooling
{
  public partial class Pool<T>
  {
    private class PoolItem : IDisposable
    {
      public PoolItem(T pooledItem)
      {
        this.PooledItem = pooledItem;
        this.LastRelese = DateTime.Now;
      }

      public T PooledItem { get; private set; }

      public DateTime LastRelese { get; private set; }

      public long Age
      {
        get { return (long)DateTime.Now.Subtract(LastRelese).TotalMilliseconds; }
      }

      #region Cleanup

      public void Dispose()
      {
        if (typeof(T).GetInterface("IDisposable") != null)
          ((IDisposable)PooledItem).Dispose();
      }

      #endregion
    }
  }
}